{extend name="extra@admin/content"}

{block name="content"}

<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='layui-form' style='padding-top:20px'>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="color:#ff5722;font-size:16px;">原料</label>
             <div class="layui-input-inline" >
                 <input type="text" name="title_1" readonly class="layui-input" value="" style="border:0px;color:#ff5722;">
             </div>
             <!-- <div class="layui-input-inline" >
                 <input type="text" name="title_2"  readonly class="layui-input" value="单价" style="border:0px;color:#ff5722;font-size:16px;">
             </div> -->
             <div class="layui-input-inline" >
                 <input type="text" name="title_2"  readonly class="layui-input" value="订货数量" style="border:0px;color:#ff5722;font-size:16px;">
             </div>
             <!-- <div class="layui-input-inline" >
                 <input type="text" name="title_3"  readonly class="layui-input" value="小计￥" style="border:0px;color:#ff5722;font-size:16px;">
             </div> -->
        </div>
    </div>
    {foreach name="material" item="v" key="k"}
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">原料</label>
                <div class="layui-input-inline" >
                    <input type="text" name="name[]" required="required" placeholder="" autocomplete="off" readonly class="layui-input" value="{$v.name}/{$v.unit}">
                </div>
                <div class="layui-input-inline" >
                    <input type="text" name="num[]" required="required" placeholder="请输入采购数量" pattern="^([1-9][0-9]*){1,9}$" autocomplete="off" class="layui-input" value="" >
                </div>
                <!-- <div class="layui-input-inline" >
                    <input type="text" name="price[]" required="required" readonly placeholder="" autocomplete="off" class="layui-input" value="{$v.price}">
                </div> -->
                <!-- <div class="layui-input-inline" >
                    <input type="text" name="num[]" required="required" placeholder="请输入采购数量" pattern="^([1-9][0-9]*){1,9}$" autocomplete="off" class="layui-input" value="" onblur="count_xiaoji(this);">
                </div> -->
                <!-- <div class="layui-input-inline" >
                    <input type="text" name="xiaoji[]" required="required" placeholder="小计" pattern="(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)" autocomplete="off" class="layui-input" value="" onblur="count_zongji(this)">
                </div> -->
                <input type="hidden" name="id[]" value="{$v.id}">
            </div>
        </div>
    {/foreach}
    <!-- <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="color:#ff5722;font-size:16px;">总计￥</label>
             <div class="layui-input-inline" >
                 <input type="text" name="zongji" readonly class="layui-input" value="0" style="color:#ff5722;">
             </div>
        </div>
    </div> -->


    <div class="hr-line-dashed" id="add"></div>
    <div class="col-sm-4 col-sm-offset-2">
        <div class="layui-form-item text-center">
            <input type="hidden" name="type" value="{$type}">
            <a  href="javascript:history.back(-1)" class='layui-btn' style="background:#ff5722;">返回</a>
            <button class="layui-btn" type="submit" >生成订单</button>
        </div>
    </div>
    <script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;      //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });

    /**
     *  计算小计
     * @param obj
     */
    function count_xiaoji(obj){
        var price = $(obj).parent().parent().find('input[name="price[]"]').val();
        var xiaoji = parseFloat(price)*parseInt($(obj).val());
        var zongji = 0;
        $(obj).parent().parent().find('input[name="xiaoji[]"]').val(xiaoji);

        $( "input[name='xiaoji[]']").each(function(da,i){       //计算总计价格
            if($('input[name="xiaoji[]"]').eq(da).val() != ''){
                zongji = zongji+parseFloat($('input[name="xiaoji[]"]').eq(da).val());
            }
        });

        $('input[name=zongji]').val(zongji);
    }

    /**
     * 计算总计
     */
    function count_zongji(obj){
        var zongji = 0;
        $( "input[name='xiaoji[]']").each(function(da,i){       //计算总计价格
            if($('input[name="xiaoji[]"]').eq(da).val() != ''){
                zongji = zongji+parseFloat($('input[name="xiaoji[]"]').eq(da).val());
            }
        });

        $('input[name=zongji]').val(zongji);
    }
    </script>
</form>

{/block}